package com.spic.business.registrationform.controller;


import com.spic.business.registrationform.domain.ArchiveStaffWorkExperience;
import com.spic.business.registrationform.service.IArchiveStaffWorkExperienceService;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 员工工作经历Controller
 * 
 * @author spic
 * @date 2022-07-20
 */
@RestController
@RequestMapping("/experience")
public class ArchiveStaffWorkExperienceController extends BaseController
{
    @Autowired
    private IArchiveStaffWorkExperienceService archiveStaffWorkExperienceService;

    /**
     * 查询员工工作经历列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ArchiveStaffWorkExperience archiveStaffWorkExperience)
    {
        startPage();
        List<ArchiveStaffWorkExperience> list = archiveStaffWorkExperienceService.selectArchiveStaffWorkExperienceList(archiveStaffWorkExperience);
        return getDataTable(list);
    }

    /**
     * 导出员工工作经历列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArchiveStaffWorkExperience archiveStaffWorkExperience) throws IOException {
        List<ArchiveStaffWorkExperience> list = archiveStaffWorkExperienceService.selectArchiveStaffWorkExperienceList(archiveStaffWorkExperience);
        ExcelUtil<ArchiveStaffWorkExperience> util = new ExcelUtil<ArchiveStaffWorkExperience>(ArchiveStaffWorkExperience.class);
        util.exportExcel(response, list, "员工工作经历数据");
    }

    /**
     * 获取员工工作经历详细信息
     */
    @GetMapping(value = "/{experienceId}")
    public AjaxResult getInfo(@PathVariable("experienceId") Long experienceId)
    {
        return AjaxResult.success(archiveStaffWorkExperienceService.selectArchiveStaffWorkExperienceByExperienceId(experienceId));
    }

    /**
     * 新增员工工作经历
     */
    @PostMapping
    public AjaxResult add(@RequestBody ArchiveStaffWorkExperience archiveStaffWorkExperience)
    {
        return toAjax(archiveStaffWorkExperienceService.insertArchiveStaffWorkExperience(archiveStaffWorkExperience));
    }

    /**
     * 修改员工工作经历
     */
    @PutMapping
    public AjaxResult edit(@RequestBody ArchiveStaffWorkExperience archiveStaffWorkExperience)
    {
        return toAjax(archiveStaffWorkExperienceService.updateArchiveStaffWorkExperience(archiveStaffWorkExperience));
    }

    /**
     * 删除员工工作经历
     */
	@DeleteMapping("/{experienceIds}")
    public AjaxResult remove(@PathVariable Long[] experienceIds)
    {
        return toAjax(archiveStaffWorkExperienceService.deleteArchiveStaffWorkExperienceByExperienceIds(experienceIds));
    }
}
